!(function ($) {
    var ui     = {
        title : $('.sse_title_common h2'),
        menu  : $('.market_menu'),
    };
    var cache_url = ui.menu[0].getAttribute('data-post');          //缓存post url
    var type   = null;
    var time   = showTime();
    var market = new Vue({
        el : "#marketdata",
        data : {
            time : time,
            list : ''
        }
    });

    function fetchdata(url,type) {
        $.post(url).then(function (res) {
            var rd = JSON.parse(res);
            if(type=='y') {
                //处理原油数据
                var arr   = [];
                var list1 = rd.data.list[0].list;
                var list2 = rd.data.list[1].list;
                for(var a in list1){
                    arr.push(list1[a]);
                }
                for(var b in list2){
                    arr.push(list2[b]);
                }
                market.list = arr;
                return ;
            }
            market.list = rd.data.list;
        })
    }

    fetchdata(cache_url,type);

    ui.menu.on('click',function () {
        var url     = this.getAttribute('data-post');
        var li      = $(this).parent('li');
        var title   = $(this).find('.ib_mid').text();
        cache_url   = url;
        type        = this.getAttribute('data-type');
        ui.title.text(title);
        li.addClass('active').siblings().removeClass('active');
        fetchdata(url,type)
    });

    //更新时间
    setInterval(function () {
        fetchdata(cache_url,type);
    },60000);

})(jQuery);